#include "options_genetic.h"

/** Nacte nastaveni z daneho XML elementu.
 * \param settings XML element s nastavenim genetickeho algoritmu
 */
void GeneticOptions::Read(ticpp::Element * settings) {
	settings->GetAttributeOrDefault("size", &generation_size, 100);
	settings->GetAttributeOrDefault("loops", &generation_count, 50);
	settings->GetAttributeOrDefault("mutation", &mutation_rate, 0.01);
	settings->GetAttributeOrDefault("original", &original, false);
}

/** Vypise do logu informace o nastaveni algoritmu
 */
void GeneticOptions::Print() {
	Log() << "Nastaveni genetickeho algoritmu: " << (original ? "PUVODNI" : "ZMENENY") << std::endl << " - velikost generace: " << generation_size << std::endl 
		<< " - mutacni faktor: " << mutation_rate << std::endl << " - pocet generaci: " << generation_count << std::endl;
}

/** Vrati popisek algoritmu.
 * \param permutation true, pokud se jedna o permutacni algoritmus
 * \return popis nastaveni genetickeho algoritmu
 */
std::string GeneticOptions::GetTitle(bool permutation) {
	char title[64];
	if (permutation) {
		sprintf(title, "S%d-C%d", generation_size, generation_count);
	}
	else {
		sprintf(title, "%cS%dC%dM%.2f", original ? 'O' : 'N', generation_size, generation_count, mutation_rate);
	}
	return title;
}
